package com.ruoyi.invest.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.invest.domain.TbInvestPact;
import com.ruoyi.invest.service.ITbInvestPactService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 投资合同Controller
 * 
 * @author ruoyi
 * @date 2023-01-14
 */
@RestController
@RequestMapping("/pact")
@CrossOrigin
public class TbInvestPactController extends BaseController
{
    @Autowired
    private ITbInvestPactService tbInvestPactService;

    /**
     * 查询投资合同列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbInvestPact tbInvestPact)
    {
        startPage();
        List<TbInvestPact> list = tbInvestPactService.selectTbInvestPactList(tbInvestPact);
        return getDataTable(list);
    }

    /**
     * 导出投资合同列表
     */
    @Log(title = "投资合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbInvestPact tbInvestPact)
    {
        List<TbInvestPact> list = tbInvestPactService.selectTbInvestPactList(tbInvestPact);
        ExcelUtil<TbInvestPact> util = new ExcelUtil<TbInvestPact>(TbInvestPact.class);
        util.exportExcel(response, list, "投资合同数据");
    }

    /**
     * 获取投资合同详细信息
     */
    @GetMapping(value = "/{investPactId}")
    public AjaxResult getInfo(@PathVariable("investPactId") Long investPactId)
    {
        return success(tbInvestPactService.selectTbInvestPactByInvestPactId(investPactId));
    }

    /**
     * 新增投资合同
     */
    @Log(title = "投资合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbInvestPact tbInvestPact)
    {
        return toAjax(tbInvestPactService.insertTbInvestPact(tbInvestPact));
    }

    /**
     * 修改投资合同
     */
    @Log(title = "投资合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbInvestPact tbInvestPact)
    {
        return toAjax(tbInvestPactService.updateTbInvestPact(tbInvestPact));
    }

    /**
     * 删除投资合同
     */
    @Log(title = "投资合同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{investPactIds}")
    public AjaxResult remove(@PathVariable Long[] investPactIds)
    {
        return toAjax(tbInvestPactService.deleteTbInvestPactByInvestPactIds(investPactIds));
    }
}
